Next | Prev | Up | Top | Contents | Index
How Devices Are Used
To use a device, a process opens the special device file by passing its pathname to open() (see the open(2) reference page). For example, a generic SCSI device might be opened by a statement such as this.
int scsi_fd = open("/dev/scsi/sc0d11l0",O_RDWR);
The returned integer is the file descriptor, a number that indexes an array of control blocks maintained by IRIX in the address space of each process. With a file descriptor, the process can call other system functions that give access to the device. Each of these system calls is implemented in the kernel by transferring control to an entry point in the device driver.
Device Driver Entry Points
Each device driver supports one or more of the following operations:
- open
- Notifies the driver that a process wants to use the device.
- close
- Notifies the driver that a process is finished with the device.
- interrupt
- Entered by the kernel upon a hardware interrupt, notes an event reported by a device, such as the completion of a device action, and possibly initiates another action.
- read
- Entered from the function read(), transfers data from the device to a buffer in the address space of the calling process.
- write
- Entered from the function write(), transfers data from the calling process's address space to the device.
- control
- Entered from the function ioctl(), performs some kind of control function specific to the type of device in use.
Not every driver supports every entry point. For example, the generic SCSI driver (see "Generic SCSI Device Driver") supports only the open, close, and control entries.
Device drivers in general are documented with the device special files they support, in volume 7 of the reference pages. For a sample, review:
- dsk(7m), documenting the standard IRIX SCSI disk device driver
- smfd(7m), documenting the diskette and optical diskette driver
- tps(7m), documenting the SCSI tape drive device driver
- plp(7), documenting the parallel line printer device driver
- klog(7), documenting a "device" driver that is not a device at all, but a special interface to the kernel
If you review a sample of entries in volume 7, as well as other reference pages that are called out in the topics in this chapter, you will understand the wide variety of functions performed by device drivers.
Next | Prev | Up | Top | Contents | Index